package io.bdmc.modules.bss.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.MyMap;
import io.bdmc.common.utils.MyPage;
import io.bdmc.common.utils.R;
import io.bdmc.common.validator.ValidatorUtils;
import io.bdmc.common.validator.group.AddGroup;
import io.bdmc.common.validator.group.UpdateGroup;
import io.bdmc.modules.bss.entity.SmkMaint;
import io.bdmc.modules.bss.model.LabelValue;
import io.bdmc.modules.bss.model.MaintParam;
import io.bdmc.modules.bss.service.ISmkMaintService;
import io.bdmc.modules.sys.controller.AbstractController;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huanglu
 * @since 2019-01-23
 */
@RestController
@RequestMapping("/bss/maint")
public class SmkMaintController  extends AbstractController{

    @Autowired
    private ISmkMaintService _maintSVs;


    @RequestMapping("/list")
	@RequiresPermissions("bss:maint:list")
	public R list(MaintParam params){
        MyPage<SmkMaint> myPage = new MyPage<SmkMaint>(params.getCurrent(), params.getSize());
        MyPage<SmkMaint> map = _maintSVs.mySelectPage(myPage, params);
		return R.ok().putData(MyMap.ok(map.getRecords(), map.getTotal()));

	}


            /**
	 * 保存维保单位
	 */
	@SysLogger("保存维保单位")
	@RequestMapping("/save")
	@RequiresPermissions("bss:maint:save")
	public R save(@RequestBody SmkMaint maint){
		ValidatorUtils.validateEntity(maint, AddGroup.class);		
		//shop.setCreateBy(getuers);
		Boolean b = maint.insert();	
		return R.trueOfFalse(b);
    }

    /**
	 * 修改维保单位
	 */
	@SysLogger("修改维保单位")
	@RequestMapping("/update")
	@RequiresPermissions("bss:maint:update")
	public R update(@RequestBody SmkMaint shop){
		ValidatorUtils.validateEntity(shop, UpdateGroup.class);
		Boolean b = shop.updateById();
		return R.trueOfFalse(b);
    }

    
    /**
	 * 删除维保单位
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("bss:maint:delete")
	public R delete(@RequestBody long maintId) {
		if(maintId>0)
		_maintSVs.removeById(maintId);
		return R.ok();
	}

	@RequestMapping("/combo")
	@RequiresPermissions("bss:maint:list")
	public R combo() {
		MyPage<SmkMaint> myPage = new MyPage<SmkMaint>(1, 100);
		List<LabelValue> list = _maintSVs.mySelectCombo(myPage);
		return R.ok().putData(list);
	}
}

